package com.doit.log_collect.flume;

import org.apache.flume.Context;
import org.apache.flume.Event;
import org.apache.flume.interceptor.Interceptor;

import java.util.List;
import java.util.Random;

/**
 * @DATE 2022/3/13/15:59
 * @Author MDK
 * @Version 2021.2.2
 **/
public class ChannelSelectorHeader implements Interceptor {

    Random r;

    @Override
    public void initialize() {
        r = new Random();
    }

    @Override
    public Event intercept(Event event) {
        String s = event.getHeaders().put("state", r.nextInt(2) + "");
        return event;
    }

    @Override
    public List<Event> intercept(List<Event> events) {
        for (Event event : events) {
            intercept(event);
        }
        return events;
    }

    @Override
    public void close() {

    }

    public static class ChannelSelectorHeaderBuilder implements Interceptor.Builder{
        @Override
        public Interceptor build() {
            return new ChannelSelectorHeader();
        }

        @Override
        public void configure(Context context) {

        }
    }
}
